package com.etrans.web.gps.business.report.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.stereotype.Service;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.report.domain.EnterpriseSwap;
import com.etrans.web.gps.common.MGTemplete;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.QueryOperators;
import com.mongodb.client.AggregateIterable;

/**
 *业户统计Service
 * @author zhangw
 *
 */
@Service
public class EnterpriseStatisticsService extends BaseService{
	
	/**
	 * 根据区域id查询车辆数和业户数
	 * @param areaId
	 */
	public HashMap<String, Object> queryVehicleAndEntCount(Integer areaId) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",areaId));
		return this.selectOne("alarmStatistics.queryVehicleAndEntCount", param);
	}
	/**
	 * 根据区域id查询区域名称
	 * @return  
	 */
	public String queryAreaNameById(Integer area_id) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",area_id));
		return this.selectOne("alarmStatistics.queryTwoAreaNameById", param);
	}
	
	/**
	 * 
	 * @param areaIdList
	 * @param inputDate
	 * @return
	 */
	public Map<String, Object> queryEnterpriseSwap(List<Integer> areaIdList, String inputDate) {
		//查询企业id
		String query_id = inputDate.substring(2, 4)+inputDate.substring(5, 7);
		Pattern pattern = Pattern.compile("^"+query_id);
		// 查询条件
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		whereMap.put("_id", pattern);
		whereMap.put("area_id", new BasicDBObject(QueryOperators.IN,areaIdList));
		HashMap<String,Object> sortMap = new HashMap<String,Object>();
		sortMap.put("vehicle_access_rate", -1);
		List<EnterpriseSwap> resultList = MGTemplete.find("egov","enterprise_swap_month",whereMap,sortMap,EnterpriseSwap.class);
		//入网率
		//Collections.sort(resultList,Collections.reverseOrder(new Com_Access()));
		List<Map<String, Object>> access = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("vehicle_count", resultList.get(i).getVehicle_count());
			map.put("vehicle_access_count", resultList.get(i).getVehicle_access_count());
			map.put("vehicle_access_rate", resultList.get(i).getVehicle_access_rate());
			access.add(map);
		}
		//上线率
		Collections.sort(resultList,Collections.reverseOrder(new Com_Online()));
		List<Map<String, Object>> online = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("vehicle_access_count", resultList.get(i).getVehicle_access_count());
			map.put("vehicle_online_count", resultList.get(i).getVehicle_online_count());
			map.put("vehicle_online_rate", resultList.get(i).getVehicle_online_rate());
			online.add(map);
		}
		//合格率
		Collections.sort(resultList,Collections.reverseOrder(new Com_Correct()));
		List<Map<String, Object>> correct = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("track_count", resultList.get(i).getTrack_normal() + 
					resultList.get(i).getException_track_count());
			map.put("track_normal", resultList.get(i).getTrack_normal());
			map.put("data_correct_rate", resultList.get(i).getData_correct_rate());
			correct.add(map);
		}
		//飘逸率
		Collections.sort(resultList,Collections.reverseOrder(new Com_Position()));
		List<Map<String, Object>> position = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			int online_count = resultList.get(i).getVehicle_online_count();
			map.put("vehicle_online_count", online_count);
			map.put("exception_vehicle_count", resultList.get(i).getException_vehicle_count());
			map.put("position_exception_rate", 
					online_count==0?0:Math.round(10000.0*resultList.get(i).getException_vehicle_count()/online_count)/100);
			position.add(map);
		}
		//回复率
		Collections.sort(resultList,Collections.reverseOrder(new Com_Reply()));
		List<Map<String, Object>> reply = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("check_count", resultList.get(i).getCheck_count());
			map.put("reply_correct_count", resultList.get(i).getReply_correct_count());
			map.put("reply_rate", resultList.get(i).getReply_rate());
			reply.add(map);
		}
		Collections.sort(resultList);
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("access", access);
		resultMap.put("online", online);
		resultMap.put("correct", correct);
		resultMap.put("position", position);
		resultMap.put("reply", reply);
		resultMap.put("score", resultList);
		return resultMap;
	}

	/**
	 * 
	 * @param areaIdList
	 * @param inputDate
	 * @return
	 */
	public List<Map<String, Object>> queryEnterpriseSwap2(List<Integer> areaIdList, String inputDate) {
		// 查询条件
		HashMap<String,Object> entparam = new HashMap<String, Object>();
		//查询企业id
		String query_id = inputDate.substring(2, 4)+inputDate.substring(5, 7);
		Pattern pattern = Pattern.compile("^"+query_id);
		entparam.put("_id", pattern);
		entparam.put("area_id", new BasicDBObject(QueryOperators.IN,areaIdList));
		List<Bson> bson = new ArrayList<Bson>();
	    bson.add(new BasicDBObject("$match", entparam));
	    //group
        DBObject groupFields = new BasicDBObject("_id", "$enterprise_id");
        groupFields.put("gap_time", new BasicDBObject("$sum","$sum_gap_time"));
        groupFields.put("total_time", new BasicDBObject("$sum", "$sum_total_time"));
        Bson group = new BasicDBObject("$group", groupFields);
        bson.add(group);
		AggregateIterable<Document> entList = MGTemplete.getCollection("egov","vehicle_swap_month").aggregate(bson);
		Map<Integer, String> entMap = new HashMap<Integer, String>();
		for (Document doc : entList) {
			entMap.put(doc.getInteger("_id"), doc.getDouble("gap_time").longValue()+"_"+doc.getDouble("total_time").longValue());
		}
		// 查询条件
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		whereMap.put("_id", pattern);
		whereMap.put("area_id", new BasicDBObject(QueryOperators.IN,areaIdList));
		HashMap<String,Object> sortMap = new HashMap<String,Object>();
		sortMap.put("track_complete_rate", -1);
		List<EnterpriseSwap> resultList = MGTemplete.find("egov","enterprise_swap_month",whereMap,sortMap,EnterpriseSwap.class);
		//完整率
		List<Map<String, Object>> complete = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			String time = entMap.get(resultList.get(i).getEnterprise_id());
			Long gap_time = 0L;
			Long total_time = 0L;
			if (time != null && time.split("_").length==2) {
				gap_time = Long.valueOf(time.split("_")[0])/3600;
				total_time = Long.valueOf(time.split("_")[1])/3600;
			}
			map.put("sum_total_time", total_time);
			map.put("sum_gap_time", gap_time);
			map.put("track_complete_rate", total_time==0?0:Math.round(10000.0*gap_time/total_time)/100);
			complete.add(map);
		}
		return complete;
	}
	
	/**
	 * 
	 * @param areaIdList
	 * @param inputDate
	 * @return
	 */
	public Map<String, Object> exportEnterpriseSwap(List<Integer> areaIdList, String inputDate) {
		// 查询条件
		HashMap<String,Object> entparam = new HashMap<String, Object>();
		//查询企业id
		String query_id = inputDate.substring(2, 4)+inputDate.substring(5, 7);
		Pattern pattern = Pattern.compile("^"+query_id);
		entparam.put("_id", pattern);
		entparam.put("area_id", new BasicDBObject(QueryOperators.IN,areaIdList));
		List<Bson> bson = new ArrayList<Bson>();
	    bson.add(new BasicDBObject("$match", entparam));
	    //group
        DBObject groupFields = new BasicDBObject("_id", "$enterprise_id");
        groupFields.put("gap_time", new BasicDBObject("$sum","$sum_gap_time"));
        groupFields.put("total_time", new BasicDBObject("$sum", "$sum_total_time"));
        Bson group = new BasicDBObject("$group", groupFields);
        bson.add(group);
        AggregateIterable<Document> entList = MGTemplete.getCollection("egov","vehicle_swap_month").aggregate(bson);
		Map<Integer, String> entMap = new HashMap<Integer, String>();
		for (Document doc : entList) {
			entMap.put(doc.getInteger("_id"), doc.getDouble("gap_time").longValue()+"_"+doc.getDouble("total_time").longValue());
		}
		// 查询条件
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		whereMap.put("_id", pattern);
		whereMap.put("area_id", new BasicDBObject(QueryOperators.IN,areaIdList));
		HashMap<String,Object> sortMap = new HashMap<String,Object>();
		sortMap.put("vehicle_access_rate", -1);
		List<EnterpriseSwap> resultList = MGTemplete.find("egov","enterprise_swap_month",whereMap,sortMap,EnterpriseSwap.class);
		Map<String, Object> resultMap = new HashMap<>();
		//入网率
		int size = resultList.size();
		int vehicleSum = 0;
		int accessSum = 0;
		//Collections.sort(resultList,Collections.reverseOrder(new Com_Access()));
		List<Map<String, Object>> access = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			vehicleSum += resultList.get(i).getVehicle_count();
			accessSum += resultList.get(i).getVehicle_access_count();
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("vehicle_count", resultList.get(i).getVehicle_count());
			map.put("vehicle_access_count", resultList.get(i).getVehicle_access_count());
			map.put("vehicle_access_rate", resultList.get(i).getVehicle_access_rate());
			access.add(map);
		}
		resultMap.put("access", access);
		resultMap.put("vehicleSum", vehicleSum);
		resultMap.put("enterpiseSum", size);
		resultMap.put("accessSum", accessSum);
		resultMap.put("accessRate", vehicleSum==0?0:(Math.ceil(10000.0*accessSum/vehicleSum)/100));
		resultMap.put("heightAccess1", size>0?resultList.get(0).getEnterprise_name():"");
		resultMap.put("heightAccess2", size>1?resultList.get(1).getEnterprise_name():"");
		resultMap.put("heightAccess3", size>2?resultList.get(2).getEnterprise_name():"");
		resultMap.put("accessRate1", size>0?resultList.get(0).getVehicle_access_rate():"");
		resultMap.put("accessRate2", size>1?resultList.get(1).getVehicle_access_rate():"");
		resultMap.put("accessRate3", size>2?resultList.get(2).getVehicle_access_rate():"");
		resultMap.put("lowAccess1", size>0?resultList.get(size-1).getEnterprise_name():"");
		resultMap.put("lowAccess2", size>1?resultList.get(size-2).getEnterprise_name():"");
		resultMap.put("lowAccess3", size>2?resultList.get(size-3).getEnterprise_name():"");
		resultMap.put("accessRate4", size>0?resultList.get(size-1).getVehicle_access_rate():"");
		resultMap.put("accessRate5", size>1?resultList.get(size-2).getVehicle_access_rate():"");
		resultMap.put("accessRate6", size>2?resultList.get(size-3).getVehicle_access_rate():"");
		//上线率
		int onlineSum = 0;
		Collections.sort(resultList,Collections.reverseOrder(new Com_Online()));
		List<Map<String, Object>> online = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			onlineSum += resultList.get(i).getVehicle_online_count();
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("vehicle_access_count", resultList.get(i).getVehicle_access_count());
			map.put("vehicle_online_count", resultList.get(i).getVehicle_online_count());
			map.put("vehicle_online_rate", resultList.get(i).getVehicle_online_rate());
			online.add(map);
		}
		resultMap.put("online", online);
		resultMap.put("onlineSum", onlineSum);
		resultMap.put("onlineRate", accessSum==0?0:(Math.ceil(10000.0*onlineSum/accessSum)/100));
		resultMap.put("heightOnline1", size>0?resultList.get(0).getEnterprise_name():"");
		resultMap.put("heightOnline2", size>1?resultList.get(1).getEnterprise_name():"");
		resultMap.put("heightOnline3", size>2?resultList.get(2).getEnterprise_name():"");
		resultMap.put("onlineRate1", size>0?resultList.get(0).getVehicle_online_rate():"");
		resultMap.put("onlineRate2", size>1?resultList.get(1).getVehicle_online_rate():"");
		resultMap.put("onlineRate3", size>2?resultList.get(2).getVehicle_online_rate():"");
		resultMap.put("lowOnline1", size>0?resultList.get(size-1).getEnterprise_name():"");
		resultMap.put("lowOnline2", size>1?resultList.get(size-2).getEnterprise_name():"");
		resultMap.put("lowOnline3", size>2?resultList.get(size-3).getEnterprise_name():"");
		resultMap.put("onlineRate4", size>0?resultList.get(size-1).getVehicle_online_rate():"");
		resultMap.put("onlineRate5", size>1?resultList.get(size-2).getVehicle_online_rate():"");
		resultMap.put("onlineRate6", size>2?resultList.get(size-3).getVehicle_online_rate():"");
		//合格率
		int track_normal = 0;
		int track_total = 0;
		int sum_total_time = 0;
		int sum_gap_time = 0;
		Collections.sort(resultList,Collections.reverseOrder(new Com_Correct()));
		List<Map<String, Object>> correct = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			track_normal += resultList.get(i).getTrack_normal();
			track_total += track_normal + resultList.get(i).getException_track_count();
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("track_total", resultList.get(i).getTrack_normal() +  resultList.get(i).getException_track_count());
			map.put("track_normal", resultList.get(i).getTrack_normal());
			map.put("data_correct_rate", resultList.get(i).getData_correct_rate());
			correct.add(map);
			Long gap_time = 0L;
			Long total_time = 0L;
			String time = entMap.get(resultList.get(i).getEnterprise_id());
			if (time != null && time.split("_").length==2) {
				total_time = Long.valueOf(time.split("_")[1])/3600;
				gap_time = Long.valueOf(time.split("_")[0])/3600;
			}
			sum_total_time += total_time;
			sum_gap_time += gap_time;
			resultList.get(i).setOverspeed_100_count(total_time.intValue());
			resultList.get(i).setSpeed_160_count(gap_time.intValue());
			resultList.get(i).setTrack_complete_rate(total_time==0?0:Math.ceil(10000.0*gap_time/total_time)/100);
		}
		resultMap.put("correct", correct);
		resultMap.put("sum_gap_time", sum_gap_time);
		resultMap.put("sum_total_time", sum_total_time);
		resultMap.put("complete_rate", sum_total_time==0?0:Math.ceil(10000.0*sum_gap_time/sum_total_time)/100);
		resultMap.put("track_total", track_total);
		resultMap.put("track_normal", track_normal);
		resultMap.put("correctRate", track_total==0?0:(Math.ceil(10000.0*track_normal/track_total)/100));
		resultMap.put("heightCorrect1", size>0?resultList.get(0).getEnterprise_name():"");
		resultMap.put("heightCorrect2", size>1?resultList.get(1).getEnterprise_name():"");
		resultMap.put("heightCorrect3", size>2?resultList.get(2).getEnterprise_name():"");
		resultMap.put("correctRate1", size>0?resultList.get(0).getData_correct_rate():"");
		resultMap.put("correctRate2", size>1?resultList.get(1).getData_correct_rate():"");
		resultMap.put("correctRate3", size>2?resultList.get(2).getData_correct_rate():"");
		resultMap.put("lowCorrect1", size>0?resultList.get(size-1).getEnterprise_name():"");
		resultMap.put("lowCorrect2", size>1?resultList.get(size-2).getEnterprise_name():"");
		resultMap.put("lowCorrect3", size>2?resultList.get(size-3).getEnterprise_name():"");
		resultMap.put("correctRate4", size>0?resultList.get(size-1).getData_correct_rate():"");
		resultMap.put("correctRate5", size>1?resultList.get(size-2).getData_correct_rate():"");
		resultMap.put("correctRate6", size>2?resultList.get(size-3).getData_correct_rate():"");
		//完整率
		Collections.sort(resultList,Collections.reverseOrder(new Com_Complete()));
		List<Map<String, Object>> complete = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("total_time", resultList.get(i).getOverspeed_100_count());
			map.put("gap_time", resultList.get(i).getSpeed_160_count());
			map.put("track_complete_rate", resultList.get(i).getTrack_complete_rate());
			complete.add(map);
		}
		resultMap.put("complete", complete);
		resultMap.put("heightComplete1", size>0?resultList.get(0).getEnterprise_name():"");
		resultMap.put("heightComplete2", size>1?resultList.get(1).getEnterprise_name():"");
		resultMap.put("heightComplete3", size>2?resultList.get(2).getEnterprise_name():"");
		resultMap.put("completeRate1", size>0?resultList.get(0).getTrack_complete_rate():"");
		resultMap.put("completeRate2", size>1?resultList.get(1).getTrack_complete_rate():"");
		resultMap.put("completeRate3", size>2?resultList.get(2).getTrack_complete_rate():"");
		resultMap.put("lowComplete1", size>0?resultList.get(size-1).getEnterprise_name():"");
		resultMap.put("lowComplete2", size>1?resultList.get(size-2).getEnterprise_name():"");
		resultMap.put("lowComplete3", size>2?resultList.get(size-3).getEnterprise_name():"");
		resultMap.put("completeRate4", size>0?resultList.get(size-1).getTrack_complete_rate():"");
		resultMap.put("completeRate5", size>1?resultList.get(size-2).getTrack_complete_rate():"");
		resultMap.put("completeRate6", size>2?resultList.get(size-3).getTrack_complete_rate():"");
		//飘逸率
		Collections.sort(resultList,Collections.reverseOrder(new Com_Position()));
		int exception_vehicle = 0;
		List<Map<String, Object>> position = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			exception_vehicle +=  resultList.get(i).getException_vehicle_count();
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			int online_count = resultList.get(i).getVehicle_online_count();
			map.put("vehicle_online_count", online_count);
			map.put("exception_vehicle_count", resultList.get(i).getException_vehicle_count());
			double positionRate = online_count==0?0:Math.ceil(10000.0*resultList.get(i).getException_vehicle_count()/online_count)/100;
			map.put("position_exception_rate", positionRate);
			resultList.get(i).setPosition_exception_rate(positionRate);
			position.add(map);
		}
		resultMap.put("position", position);
		resultMap.put("exception_vehicle", exception_vehicle);
		resultMap.put("position_rate", onlineSum==0?0:Math.ceil(10000.0*exception_vehicle/onlineSum)/100);
		resultMap.put("heightPosition1", size>0?resultList.get(0).getEnterprise_name():"");
		resultMap.put("heightPosition2", size>1?resultList.get(1).getEnterprise_name():"");
		resultMap.put("heightPosition3", size>2?resultList.get(2).getEnterprise_name():"");
		resultMap.put("positionRate1", size>0?resultList.get(0).getPosition_exception_rate():"");
		resultMap.put("positionRate2", size>1?resultList.get(1).getPosition_exception_rate():"");
		resultMap.put("positionRate3", size>2?resultList.get(2).getPosition_exception_rate():"");
		//回复率
		Collections.sort(resultList,Collections.reverseOrder(new Com_Reply()));
		int check_count = 0;int reply_correct_count = 0;
		List<Map<String, Object>> reply = new ArrayList<>();
		for (int i = 0; i < resultList.size(); i++) {
			check_count += resultList.get(i).getCheck_count();
			reply_correct_count += resultList.get(i).getReply_correct_count();
			Map<String, Object> map = new HashMap<>();
			map.put("ranking", i+1+"");
			map.put("enterprise_name", resultList.get(i).getEnterprise_name());
			map.put("check_count", resultList.get(i).getCheck_count());
			map.put("reply_correct_count", resultList.get(i).getReply_correct_count());
			map.put("reply_rate", resultList.get(i).getReply_rate());
			reply.add(map);
		}
		resultMap.put("reply", reply);
		resultMap.put("check_count", check_count);
		resultMap.put("sum_reply_rate", check_count==0?0:Math.ceil(10000.0*reply_correct_count/check_count)/100);
		resultMap.put("heightReply1", size>0?resultList.get(0).getEnterprise_name():"");
		resultMap.put("heightReply2", size>1?resultList.get(1).getEnterprise_name():"");
		resultMap.put("heightReply3", size>2?resultList.get(2).getEnterprise_name():"");
		resultMap.put("replyRate1", size>0?resultList.get(0).getPosition_exception_rate():"");
		resultMap.put("replyRate2", size>1?resultList.get(1).getPosition_exception_rate():"");
		resultMap.put("replyRate3", size>2?resultList.get(2).getPosition_exception_rate():"");
		resultMap.put("lowReply1", size>0?resultList.get(size-1).getEnterprise_name():"");
		resultMap.put("lowReply2", size>1?resultList.get(size-2).getEnterprise_name():"");
		resultMap.put("lowReply3", size>2?resultList.get(size-3).getEnterprise_name():"");
		resultMap.put("replyRate4", size>0?resultList.get(size-1).getPosition_exception_rate():"");
		resultMap.put("replyRate5", size>1?resultList.get(size-2).getPosition_exception_rate():"");
		resultMap.put("replyRate6", size>2?resultList.get(size-3).getPosition_exception_rate():"");
		//得分
		Collections.sort(resultList);
		for (int i = 0; i < resultList.size(); i++) {
			resultList.get(i).setRanking(i+1);
		}
		resultMap.put("score", resultList);
		resultMap.put("heightScore1", size>0?resultList.get(0).getEnterprise_name():"");
		resultMap.put("heightScore2", size>1?resultList.get(1).getEnterprise_name():"");
		resultMap.put("heightScore3", size>2?resultList.get(2).getEnterprise_name():"");
		resultMap.put("score1", size>0?resultList.get(0).getScore():"");
		resultMap.put("score2", size>1?resultList.get(1).getScore():"");
		resultMap.put("score3", size>2?resultList.get(2).getScore():"");
		resultMap.put("lowScore1", size>0?resultList.get(size-1).getEnterprise_name():"");
		resultMap.put("lowScore2", size>1?resultList.get(size-2).getEnterprise_name():"");
		resultMap.put("lowScore3", size>2?resultList.get(size-3).getEnterprise_name():"");
		resultMap.put("score4", size>0?resultList.get(size-1).getScore():"");
		resultMap.put("score5", size>1?resultList.get(size-2).getScore():"");
		resultMap.put("score6", size>2?resultList.get(size-3).getScore():"");
		return resultMap;
	}
	
	/**
	 * 按入网率排序
	 * @ClassName:  Com_Access  
	 * @param: Comparator<T>
	 */
	public static class Com_Access implements Comparator<EnterpriseSwap>{
		public int compare(EnterpriseSwap vo1, EnterpriseSwap vo2) {
	        return vo1.getVehicle_access_rate()-vo2.getVehicle_access_rate()>0?1:-1;
		}
	}
	
	
	/**
	 * 按上线率排序
	 * @ClassName:  Com_Online  
	 * @param: Comparator<T>
	 */
	public static class Com_Online implements Comparator<EnterpriseSwap>{
		public int compare(EnterpriseSwap vo1, EnterpriseSwap vo2) {
	        return vo1.getVehicle_online_rate()-vo2.getVehicle_online_rate()>0?1:-1;
		}
	}
	
	/**
	 * 按数据合格率排序
	 * @ClassName:  Com_Correct  
	 * @param: Comparator<T>
	 */
	public static class Com_Correct implements Comparator<EnterpriseSwap>{
		public int compare(EnterpriseSwap vo1, EnterpriseSwap vo2) {
	        return vo1.getData_correct_rate()-vo2.getData_correct_rate()>0?1:-1;
		}
	}
	
	/**
	 * 按轨迹完整率排序
	 * @ClassName:  Com_Complete  
	 * @param: Comparator<T>
	 */
	public static class Com_Complete implements Comparator<EnterpriseSwap>{
		public int compare(EnterpriseSwap vo1, EnterpriseSwap vo2) {
	        return vo1.getTrack_complete_rate()-vo2.getTrack_complete_rate()>0?1:-1;
		}
	}
	
	/**
	 * 按车辆漂移率排序
	 * @ClassName:  Com_Position  
	 * @param: Comparator<T>
	 */
	public static class Com_Position implements Comparator<EnterpriseSwap>{
		public int compare(EnterpriseSwap vo1, EnterpriseSwap vo2) {
	        return 1.0*vo1.getException_vehicle_count()/vo1.getVehicle_online_count()-1.0*vo2.getException_vehicle_count()/vo2.getVehicle_online_count()>0?1:-1;
		}
	}
	
	/**
	 * 按回复率排序
	 * @ClassName:  Com_Reply  
	 * @param: Comparator<T>
	 */
	public static class Com_Reply implements Comparator<EnterpriseSwap>{
		public int compare(EnterpriseSwap vo1, EnterpriseSwap vo2) {
	        return vo1.getReply_rate()-vo2.getReply_rate()>0?1:-1;
		}
	}
	
	/**
	 * 按得分排序
	 * @ClassName:  Com_Score 
	 * @param: Comparator<T>
	 */
	public static class Com_Score implements Comparator<EnterpriseSwap>{
		public int compare(EnterpriseSwap vo1, EnterpriseSwap vo2) {
			int re = 1;
			if (vo1.getScore()-vo2.getScore()<0) {
				re = -1;
			}else if (vo1.getScore()==vo2.getScore()) {
				if (vo1.getVehicle_access_rate()-vo2.getVehicle_access_rate()<0) {
					re = -1;
				}else if (vo1.getVehicle_access_rate()==vo2.getVehicle_access_rate()) {
					if (vo1.getVehicle_online_rate()-vo2.getVehicle_online_rate()<0) {
						re = -1;
					}else if (vo1.getVehicle_online_rate()==vo2.getVehicle_online_rate()) {
						if (vo1.getTrack_complete_rate()-vo2.getTrack_complete_rate()<0) {
							re = -1;
						}else if (vo1.getTrack_complete_rate()==vo2.getTrack_complete_rate()) {
							if (vo1.getData_correct_rate()-vo2.getData_correct_rate()<0) {
								re = -1;
							}
						}
					}
				}
			}
	        return re;
		}
	}

}
